import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        count: 0,
        info: {
            'name': '小明',
            'sex': '男'
        }
    },
    mutations: {
        inc(state, info) {
            // state.count += num
            console.log(info);
        },
        dec(state, obj) {
            state.count -= obj.num
        },
        add(state) {
            //Vue.set(state.info, 'like', '吃东西');
            //Vue.delete(state.info, 'sex')
        },
        chatime(state, info) {
            Vue.set(state.info, 'age', '66')
            console.log(info);
        }
    },
    actions: {
        achatime(context, info) {

            /*setTimeout(() => {
                context.commit('chatime', info)
                info.success();
            }, 1000)*/

          return new Promise((resolve, reject) => {
            setTimeout(() => {
              context.commit('chatime', info)
              resolve()
            }, 1000)
          })
        }
    }
})
